package com.dehui.traders.ui.web;

import android.content.Context;
import android.content.Intent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.dehui.traders.R;
import com.dehui.traders.BR;
import com.dehui.traders.databinding.ActivityWebDetailBinding;
import com.dehui.traders.ui.base.AppActvity;


public class WebDetailActivity extends AppActvity<ActivityWebDetailBinding,WebDetailViewModel> {

    public static final String IntentKey_Title = "IntentKey_Title";
    public static final String Intentkey_Url = "Intentkey_Url";

    @Override
    public int initContentView() {
        return R.layout.activity_web_detail;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public WebDetailViewModel initViewModel() {
        return new WebDetailViewModel(this);
    }

    public static void start(Context context, String title, String url) {
        Intent intent = new Intent(context,WebDetailActivity.class);
        intent.putExtra(IntentKey_Title,title);
        intent.putExtra(Intentkey_Url,url);
        context.startActivity(intent);
    }

    @Override
    public void initData() {
        super.initData();
        String title = getIntent().getStringExtra(IntentKey_Title);
        String url = getIntent().getStringExtra(Intentkey_Url);
        initToolbar("返回",title);
        WebSettings settings = binding.webView.getSettings();
        settings.setBuiltInZoomControls(false);
        settings.setDisplayZoomControls(false);
        settings.setSupportZoom(true);
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        binding.webView.loadUrl(url);
        binding.webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });

    }


}
